﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using QRCoder;

namespace QRCodeTest
{
    class Program
    {
        static void Main(string[] args)
        {
            //TestBedCode();
            TestRoomCode();
            //TestOrgCode();
        }

        static void TestBedCode()
        {
            string strCode = "http://dp.fanzhuo.net.cn/ec/employee/electronicCard/institution?id=FDE75947-63F6-481F-A3F9-0BF07D409CC5";
            QRCodeGenerator qrGenerator = new QRCoder.QRCodeGenerator();
            QRCodeData qrCodeData = qrGenerator.CreateQrCode(strCode, QRCodeGenerator.ECCLevel.Q);
            QRCode qrcode = new QRCode(qrCodeData);

            var logo = new Bitmap(@"Source\logo.png");
            var bC = Color.FromArgb(255, 242, 233);
            var bit = qrcode.GetGraphic(10, Color.Black, bC, icon: logo, drawQuietZones: false);
            bit.Save("D:\\test.png");

            var pk = Bitmap.FromFile(@"Source\床位.png");
            var g = Graphics.FromImage(pk);

            var font = new Font("黑体", 60.5f, FontStyle.Bold);
            var msg = "0200 床";
            var size = g.MeasureString(msg, font);
            var x = pk.Width / 2 - size.Width / 2;
            g.DrawString(msg, font, new SolidBrush(Color.FromArgb(129, 83, 45)), x, 120);

            var font2 = new Font("黑体", 18.5f, FontStyle.Regular);
            var msg2 = "厦门莲花恩慧养老院（同安区社会福利中心）";
            var size2 = g.MeasureString(msg2, font2);
            var x2 = 171 + 772 / 2 - size2.Width / 2;
            g.DrawString(msg2, font2, new SolidBrush(Color.Black), x2, 277 + 722 + 5);

            g.DrawImage(bit, new Rectangle(171, 277, 722, 722));

            pk.Save("Source\\testBed.png");
        }

        static void TestRoomCode()
        {
            string strCode = "http://dp.fanzhuo.net.cn/ec/employee/electronicCard/institution?id=FDE75947-63F6-481F-A3F9-0BF07D409CC5";
            QRCodeGenerator qrGenerator = new QRCoder.QRCodeGenerator();
            QRCodeData qrCodeData = qrGenerator.CreateQrCode(strCode, QRCodeGenerator.ECCLevel.Q);
            QRCode qrcode = new QRCode(qrCodeData);

            var logo = new Bitmap(@"Source\logo.png");
            var bC = Color.FromArgb(0xfff2e9);
            var bit = qrcode.GetGraphic(20, Color.Black, bC, icon: logo, drawQuietZones: false);


            var pk = Bitmap.FromFile(@"Source\房间.png");
            var g = Graphics.FromImage(pk);

            var font = new Font("黑体", 37.5f, FontStyle.Bold);
            var msg = "双人间 303";
            var size = g.MeasureString(msg, font);
            var x = pk.Width / 2 - size.Width / 2;
            g.DrawString(msg, font, new SolidBrush(Color.White), x, 34);

            var font2 = new Font("黑体", 18.5f, FontStyle.Regular);
            var msg2 = "厦门莲花恩慧养老院（同安区社会福利中心）";
            var size2 = g.MeasureString(msg2, font2);
            var x2 = 91 + 700 / 2 - size2.Width / 2;
            g.DrawString(msg2, font2, new SolidBrush(Color.Black), x2, 700 + 204 + 5);

            g.DrawImage(bit, new Rectangle(91, 204, 700, 700));

            pk.Save("Source\\testRoom.png");
        }

        static void TestOrgCode()
        {
            string strCode = "http://dp.fanzhuo.net.cn/ec/employee/electronicCard/institution?id=FDE75947-63F6-481F-A3F9-0BF07D409CC5";
            QRCodeGenerator qrGenerator = new QRCoder.QRCodeGenerator();
            QRCodeData qrCodeData = qrGenerator.CreateQrCode(strCode, QRCodeGenerator.ECCLevel.Q);
            QRCode qrcode = new QRCode(qrCodeData);

            var logo = new Bitmap(@"Source\logo.png");
            var bC = Color.FromArgb(0xfff2e9);
            var bit = qrcode.GetGraphic(20, Color.Black, bC, icon: logo, drawQuietZones: false);


            var pk = Bitmap.FromFile(@"Source\机构.png");
            var g = Graphics.FromImage(pk);

            var font = new Font("黑体", 18.5f, FontStyle.Regular);
            var msg = "厦门莲花恩慧养老院（同安区社会福利中心）";
            var size = g.MeasureString(msg, font);
            var x = 82 + 606 / 2 - size.Width / 2;
            g.DrawString(msg, font, new SolidBrush(Color.Black), x, 606 + 142 + 20);

            g.DrawImage(bit, new Rectangle(82, 142, 606, 606));

            pk.Save("Source\\testOrg.png");
        }
    }
}
